<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>欢迎欢迎</h1>
    <form>
        <input type="text" name="" id="phone" placeholder="请输入你的手机号码">
        <br>
        <br>

        <input type="password" name="" id="password" placeholder="请输入你的密码">
        <br>
        <br>
        <input type="text" name="" id="yanzhengma" placeholder="请输入你的验证码">
        <br>
        <br>

        &emsp13;&emsp13;&emsp13;&emsp13;&emsp13;&emsp13;<input type="button" name="" id="submit" value="提交" onclick="RegisterFunction()">
    </form>
    
    <script>

        var phone = document.getElementById("phone").value
        var password = document.getElementById("password").value
        var yanzhengma = document.getElementById("yanzhengma").value


        // alert(phone)
        function RegisterFunction() {

            var xmlhttp;

            if (window.XMLHttpRequest) {

                // IE7+, Firefox, Chrome ,Opera, Safari 浏览器执行代码
                xmlhttp = new XMLHttpRequest();
            }
            else{

                //IE6, IE5 浏览器执行代码
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }

            xmlhttp.onreadystatechange = function() {

                if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                    // console.log(xmlhttp.responseText)
                    console.log(xmlhttp.responseText);
                    // document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
                    var result = JSON.parse(xmlhttp.responseText);

                    if (result.status == 1){
                        alert("注册成功");
                    }else{
                        alert(result.errorMsg);
                    };

                };
            };

            xmlhttp.open("POST", "http://127.0.0.1:5000/register", true); //http://192.168.157.111:5010/register

            // xmlhttp.setRequestHeader("Content-type", "applicattion/x-www-form-urlencoded");
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

            xmlhttp.send("phone=" + phone +"&yanzhengma=" + yanzhengma +"&pass_word=" + password  );
            
        }

        // RegisterFunction()
    </script>

</body>
</html>